<template>
  <div class="home-page white-bg">
    <div class="user-wrapper">
      <div class="user-info">
        <img :src="avatar_url" class="user-avatar" />
        <div class="info-box">
          <div class="info-title">早上好，{{ userName }}</div>
          <div class="info-desc">欢迎使用，伏羲東方数字化智慧云平台</div>
        </div>
      </div>
      <div class="user-tools">
        <div class="tools-item" @click="handleToFeedback">
          <img class="tools-icon" src="@/assets/common/icon-question.png" />
          <div class="tools-content">问题反馈</div>
        </div>
        <div class="tools-item" @click="handleToQuestion">
          <img class="tools-icon" src="@/assets/common/icon-question.png" />
          <div class="tools-content">常见问题</div>
        </div>
        <div class="tools-item" @click="handleOpenPDF">
          <img class="tools-icon" src="@/assets/common/icon-doc.png" />
          <div class="tools-content">用户手册</div>
        </div>
      </div>
    </div>
    <div class="column-box">
      <div class="column-title">我的数据</div>
      <div class="tools-box">
        <div class="tools-item" v-for="(item, index) in toolList" :key="index">
          <div class="tools-icon">
            <img :src="item.icon" class="icon-img" alt="" />
          </div>
          <div class="tools-content">
            <div class="tools-title">{{ item.name }}</div>
            <div class="tools-value">{{ item.value }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="column-box">
      <div class="column-title">常用功能</div>
      <div class="list-box">
        <div
          class="list-item"
          v-for="(item, index) in listData"
          :key="index"
          @click="handleTo(item)"
          :style="{
            background: 'url(' + item.icon + ') no-repeat center',
            backgroundSize: '100%',
          }"
        >
          <div class="list-img">
            <!-- <img :src="item.icon" class="icon-img" alt="" /> -->
          </div>
          <div class="list-title">{{ item.name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref,onMounted,computed } from "vue";
import { useRouter } from "vue-router";
import { useGlobalStore } from "@/store/modules/global";
import api from "@/api";
const store = useGlobalStore();
const router = useRouter();
const userName = computed(() =>  JSON.parse(localStorage.getItem("userInfo"))?.real_name);
const avatar_url = computed(() =>  JSON.parse(localStorage.getItem("userInfo"))?.avatar_url) || "./data/user-avatar.jpeg";
const handleTo = (item) => {
  store.clearSubTitle();
  store.setTile(item.name);
  router.push(item.path);
};
const toolList = ref([
  {
    name: "实验器材",
    icon: "./images/operation/home-tool-1.png",
    value: 99,
  },
  {
    name: "器材报修",
    icon: "./images/operation/home-tool-2.png",
    value: "12/99",
  },
  // {
  //   name: "校本实验",
  //   icon: "./images/operation/home-tool-3.png",
  //   value: 99,
  // },
  {
    name: "教师数量",
    icon: "./images/operation/home-tool-4.png",
    value: 99,
  },
  {
    name: "学生数量",
    icon: "./images/operation/home-tool-5.png",
    value: 99,
  },
]);
const listData = ref([
  { name: "数据展板", icon: "./images/operation/icon-home-1.png",path:'/screen-data' },
  // { name: "校本实验", icon: "./images/operation/icon-home-2.png",path:'/school-based-experiments' },
  { name: "器材管理", icon: "./images/operation/icon-home-3.png",path:'/experiment-equipment-manage' },
  { name: "教师管理", icon: "./images/operation/icon-home-4.png",path:"/teacher-account-management" },
  // { name: "直播会议", icon: "./images/operation/icon-home-5.png" }
]);
const handleToQuestion = () => {
    router.push("/question");
}
const handleToFeedback = () => {
    router.push("/feedback");
}

const handleOpenPDF = () => {
  window.open("https://lib.fantasy-lab.com/api/StudentExperiment/PdfForStudentExperiment?student_experiment_id=5d917fbb9bd141f98871f1976f794a7a", "_blank");
}
const datas =ref()
const getData = async() => {
  const res = await  api.apiDashboardSchoolManagerDashboardDataPost({});
  datas.value = res.data
  toolList.value[0].value = res.data.equipments_count
  toolList.value[1].value = res.data.equipments_has_repair_count+'/'+res.data.equipments_count
  // toolList.value[2].value = res.data.customer_experiment_count
  toolList.value[2].value = res.data.teachers_count
  toolList.value[3].value = res.data.students_count
};
onMounted(() => {
  getData();
});
</script>
<style lang="less" scoped>
.home-page {
  padding: 0 16px;
  min-height: 100%;
  .user-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 0;
    border-bottom: 1px solid #e6ebf1;
    flex-wrap: wrap;
    .user-info {
      display: flex;
      align-items: center;
        @media screen and (max-width: 768px) {
          margin-bottom: 25px;
        }
      .user-avatar {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: #ccc;
        margin-right: 10px;
      }
      .info-box {
        .info-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 18px;
          color: #262626;
          line-height: 26px;
          text-align: left;
          font-style: normal;
          margin-bottom: 3px;
        }
        .info-desc {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #595959;
          line-height: 20px;
          text-align: left;
          font-style: normal;
        }
      }
    }
    .user-tools {
      display: flex;
      align-items: center;
      .tools-item {
        width: 116px;
        height: 46px;
        cursor: pointer;
        background: linear-gradient(
          270deg,
          rgba(39, 189, 247, 0.1) 0%,
          rgba(47, 125, 251, 0.1) 100%
        );
        border-radius: 8px;
        margin-left: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        &:last-child {
          background: linear-gradient(
            270deg,
            rgba(253, 164, 36, 0.1) 0%,
           rgba(253, 117, 58, 0.1) 100%
          );
        }
        .tools-icon {
          width: 23px;
          height: 22px;
          margin-right: 14px;
        }
        .tools-content {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #262626;
          line-height: 20px;
          text-align: left;
          font-style: normal;
        }
      }
    }
    .user-menu {
      height: 40px;

      margin-bottom: 25px;
      background: #ffffff;
      border: 1px solid #bec4ca;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 8px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 14px;
      cursor: pointer;
      color: #262626;
      .icon-link {
        width: 16px;
        height: 16px;
        background: url("@/assets/icon-link.png") no-repeat;

        margin-left: 5px;
      }
    }
  }
  .column-box {
    margin-top: 14px;
    .column-title {
      padding: 16px 0;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 16px;
      color: #262626;
      line-height: 22px;
    }
  }
  .tools-box {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    .tools-item {
      width: 216px;
      padding: 18px 0;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      position: relative;
      @media screen and (max-width: 768px) {
        width: 50%;
        flex: auto;
        margin-bottom: 12px;
      }
      &::after {
        position: absolute;
        right: 0;
        content: "";
        top: 18px;
        bottom: 18px;
        width: 1px;
        box-shadow: inset -1px 0 0px 0px #e6ebf1;
      }
      &:last-child {
        &::after {
          display: none;
        }
      }
      .tools-icon {
        width: 46px;
        height: 46px;
        margin-right: 12px;
        .icon-img {
          width: 46px;
          height: 46px;
        }
      }
      .tools-content {
        .tools-title {
          font-family: PingFangSC-Regular;
          font-weight: 400;
          font-size: 14px;
          line-height: 20px;
          color: #262626;
        }
        .tools-value {
          font-family: PingFangSC-Medium;
          font-weight: 500;
          font-size: 18px;
          color: #262626;
          letter-spacing: 0;
          line-height: 26px;
        }
      }
    }
  }
  .list-box {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -12px;
    @media screen and (max-width: 768px) {
      justify-content: center;
    }
    .list-item:hover {
      transform: scale(1.05);
    }
    .list-item {
      width: 200px;
      height: 250px;
      background-color: #e6f5ff;
      background-position: center center;
      background-repeat: no-repeat;
      border-radius: 12px;
      box-sizing: border-box;
      padding: 12px;
      cursor: pointer;
      margin: 0 12px 23px 12px;
      .list-img {
        height: 180px;
        margin-bottom: 12px;
        .icon-img {
          width: 176px;
          height: 180px;
        }
      }
      .list-title {
        width: 176px;
        height: 46px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-top: 1px solid #2626260f;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        font-size: 14px;
        color: #262626;
        text-align: center;
      }
    }
  }
}
</style>
